package wei.xinya.sort;

public class BubbleSort {
    public static void main(String[] args) {
        int[] num = {45, 78, 14, 52, 11, 64, 55, 99, 17, 18};
        bubbleSort(num);
        System.out.println(arrayToString(num));
    }

    public static void bubbleSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    private static String arrayToString(int[] arr) {
        StringBuilder str = new StringBuilder("排序后：");
        for (int a : arr) {
            str.append(a).append(" ");
        }
        return str.toString();
    }
}
